package com.hzeport.bgs22emduty.util;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 路径
 */
public class PathFilterUtil {

    public static Boolean filterName(String name){
        Pattern pattern = Pattern.compile("[^\\s\\\\/:\\*\\?\\\"<>\\|](\\x20|[^\\s\\\\/:\\*\\?\\\"<>\\|])*[^\\s\\\\/:\\*\\?\\\"<>\\|\\.]$");
        Matcher matcher = pattern.matcher(name);
        boolean result = matcher.matches();
        return result;
    }

    public static Boolean filterPath(String path){
        Pattern compile = Pattern.compile("[a-zA-Z/\\\\:]*");
        Matcher matcher = compile.matcher(path);
        boolean result = matcher.matches();
        return result;
    }

    public static boolean filterAllPathName(String pathName){
        String fileName = pathName.substring(pathName.lastIndexOf(File.separator)+1);
        String filePath = pathName.replace(fileName,"");
        if(filterPath(filePath) && filterName(fileName)){
            return true;
        }else{
            return false;
        }
    }

//    public static void main(String[] args) {
//        String pathName = "/home/test/modelPath/modelExcel.xlsx";
//        boolean result = filterAllPathName(pathName);
//        System.out.println(result);
//    }

}
